/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pl.makimo.fuzzy.sets.memberships;

import pl.makimo.fuzzy.sets.ContinuousFuzzySet;


/**
 *
 * @author Mateusz Papiernik
 */
public class Type2TriangularGaussianMembershipFunction extends ContinuousMembershipFunction {
	public double a;
	public double b;
	public double c;
	public double d;
	public double diameter;
	
    public Type2TriangularGaussianMembershipFunction(double a, double b, double c, double diameter) {
		super();
		this.a = a;
		this.b = b;
		this.c = b;
		this.d = c;
		this.diameter = diameter;
	}

    public Object value(Object obj) {
    	MembershipFunction mf = null;
    	
    	double value = firstOrderValue(obj);
    	
    	mf = new GaussianMembershipFunction(value, diameter);
    	
    	return new ContinuousFuzzySet(mf, 0.0, 1.0);
    }
    
	public double firstOrderValue(Object obj) {
		double x = (Double)obj;
		
		if (x == b) return (double)1.0;
		if (x == d) return (double)0.0;
		
        if (x <= a) return (double)0.0;        
        if (a <= x && x <= b) return (double)((x-a)/(b-a));
        if (b <= x && x <= c) return (double)1.0;
        if (c <= x && x <= d) return (double)((d-x)/(d-c));
        
        return (double)0.0;
    }
}
